from fastapi import APIRouter , Request
from .base import RouterMeta
from src.constants.resultcode import ResultCode
from src.utils.response import ApiResponse
from src.utils.logger import get_logger
from src.service.get_duration import get_video_duration
from src.schemas.common import DurationRequest


logger = get_logger("capcut")
router = APIRouter()


@router.post("/get_duration",name="获取音视频时长")
def get_duration(request: Request, duration_request: DurationRequest):
    """
    获取音视频时长
    """
    try:
        duration_result = get_video_duration(duration_request.url)
        return ApiResponse.success(
            data=duration_result,
        )
    except Exception as e:
        logger.error(f"获取音视频时长失败: {str(e)}", exc_info=True)
        return ApiResponse.error(
            result_code=ResultCode.ERROR,
            message=f"获取音视频时长失败: {str(e)}",
        )



# 路由元数据配置
meta = RouterMeta(
    router=router,
    prefix="/common",
    tags=["通用"]
)